/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jdSalidasAjuste.java
 *
 * Created on 22-sep-2010, 9:21:50
 */

package Inventario;

import administracion.BeanBinding.TblBeanBindingDetalleSuministroPedido;
import administracion.BeanBinding.TblBeanBindingDetalleUbicacion;
import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import administracion.helper.VerificarDatos;
import administracion.propiedades.Propiedades;
import com.jidesoft.hints.ListDataIntelliHints;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.MaskFormatter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;

import suministros.ejb30.TO.AlmacenTO;
import suministros.ejb30.TO.CentroCostoTO;
import suministros.ejb30.TO.EmpresaTO;
import suministros.ejb30.TO.LocalidadTO;
import suministros.ejb30.TO.ProyectoTO;
import suministros.ejb30.TO.SubAlmacenTO;
import suministros.ejb30.TO.TipoTO;
import suministros.ejb30.TO.UnidadOrganizativaTO;
import suministros.ejb30.TO.ZonaTO;
import suministros.ejb30.entity.CentroCosto;
import suministros.ejb30.entity.CodPresupuestal;
import suministros.ejb30.entity.DetalleMovimiento;
import suministros.ejb30.entity.DetalleMovimientoPK;
import suministros.ejb30.entity.DetallePedidoSuministro;
import suministros.ejb30.entity.DetallePedidoSuministroPK;
import suministros.ejb30.entity.Localidad;
import suministros.ejb30.entity.Movimiento;
import suministros.ejb30.entity.Parametros;
import suministros.ejb30.entity.Pedido;
import suministros.ejb30.entity.Proyecto;
import suministros.ejb30.entity.Suministros;
import suministros.ejb30.entity.Tipo;
import suministros.ejb30.entity.UnidadOrganizativa;
import suministros.ejb30.entity.Zona;
import suministros.ejb30.helper.Utiles_Convertir;
import suministros.ejb30.helper.Utiles_Fecha;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;

/**
 *
 * @author Diana
 */
public class jdSalidasAjuste extends javax.swing.JDialog {
    private List<TblBeanBindingDetalleSuministroPedido> detallePedido= new ArrayList<TblBeanBindingDetalleSuministroPedido>();
  
    private MaskFormatter mascaraFechaIngreso;
    private JTableBinding jTableBinding;
    EmpresaTO empresa;
    jifIngresoAjusteInventario padre;
    List listaTipos = null;
    List listaTiposIngreso = null;
    String codigoSalida=null;
    private BindingGroup bindingGroup;
    /** Creates new form jdSalidasAjuste */
    public jdSalidasAjuste(jifIngresoAjusteInventario padre,java.awt.Frame parent, boolean modal, EmpresaTO empresa,TblBeanBindingDetalleSuministroPedido detallePedido) {    
        super(parent, modal);
        construirMascaras();
        initComponents();
        pack();
        this.padre=padre;
        this.empresa=empresa;
        this.detallePedido.add(detallePedido);
        llenarComboTipoMovimiento();
        llenarComboTipoIngreso();      
        this.jLabel1.setText(empresa.getRazon());
        actualizaTablaDetalle();

    }
     private void actualizaTablaDetalle() {
    this.bindingGroup = new BindingGroup();
    this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detallePedido, this.jtDetalleSuministro);

    JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${id_suministro}"));

    columnBinding0.setColumnName("ID Suministro");
    columnBinding0.setColumnClass(String.class);
    columnBinding0.setEditable(false);

    JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${desc_suministro}"));

    columnBinding1.setColumnName("Suministro");
    columnBinding1.setColumnClass(String.class);
    columnBinding1.setEditable(false);

    JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidadPedido}"));

    columnBinding2.setColumnName("Cantidad");
    columnBinding2.setColumnClass(BigDecimal.class);
    columnBinding2.setEditable(true);


    this.bindingGroup.addBinding(this.jTableBinding);
    this.bindingGroup.bind();
        int[] porcentajes= {20,60,20};
         try {
           Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
          // MiTablePrint.autoSizeTableColumns(jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jpIngresosAjuste.class.getName()).log(Level.SEVERE, null, ex);
        }


  }
     private void construirMascaras() {
    try {
      this.mascaraFechaIngreso = new MaskFormatter("##/##/####");
    } catch (ParseException ex) {
      Logger.getLogger(jpIngresosAjuste.class.getName()).log(Level.SEVERE, null, ex);
      ex.printStackTrace();
    }
  }
   
 
     
      private void llenarComboTipoMovimiento() {

        List listaTipos_cbo = this.cboBeanBindingTipo2.getLista();
        listaTipos_cbo.clear();
        try
        {
         listaTipos = Listas.getTipo_porTabla("tipo_Movimiento");

        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener tipos documentos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jpIngresosAjuste.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboTipoIngreso() {
        List listaTipos_cbo1 = this.cboBeanBindingTipo1.getLista();
        listaTipos_cbo1.clear();
        try
        {
          listaTiposIngreso = Listas.getTipo_porTabla("tipo_salida");
          this.cboBeanBindingTipo1.setLista(listaTiposIngreso);

        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Ingresos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jpIngresosAjuste.class.getName()).log(Level.SEVERE, null, ex);
        }
      } 
   private String registrarSalida() throws Exception
   {
    String  codMovimiento=null;
    Boolean requerrimientos=false;
    BigDecimal cantidadRequerida= BigDecimal.valueOf(Double.valueOf(new Float(this.jtDetalleSuministro.getValueAt(0, 2).toString()).toString()).doubleValue());
    List detalle_pedido = new ArrayList(1);
    List detalle_ingresoDev = new ArrayList(1);
    List detalle_ubicacion = new ArrayList(1);
    CodPresupuestal codigo_presupuestal=null;

    Parametros param = Listas.getParametrosID("SU1");
    String ano = param.getParam1();
    String mes = param.getParam2();

    String observacion = this.jtaObservacion.getText();

    Date fecha_pedido = new Date(VerificarDatos.verificaFecha(this.jtfFecha.getText()).getTime());
    Utiles_Fecha utf = new Utiles_Fecha(fecha_pedido);  
   
            Movimiento mov= new Movimiento();
            if ((!utf.getAnio().equalsIgnoreCase(ano)) || (!utf.getMes().equalsIgnoreCase(mes))) {
            Utiles_MensajesDialogo.mensajeAlerta("La fecha debe coincidir con el mes actual: " + ano + " - " + mes);
            }
            else{
            mov.setNumero(this.jtfNumero.getText());
            mov.setSerie(this.jtfSerie.getText());
            mov.setAnio(ano);
            mov.setMes(mes);
            mov.setFecha(fecha_pedido);
            mov.setObservacion(this.jtaObservacion.getText());
            mov.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(1)));
            mov.setEmpresa(Utiles_Convertir.convertirToEmpresa_EmpresaTO(empresa));
            mov.setTipoIngreso(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTiposIngreso.get(7)));
             int correlativo=1;
             String centro_costos=null;
             String unidad_organica=null;
             String cod_presupuestal=null;
             String cod_proyecto=null;
             String cod_inversion=null;
             String ctacble=null;

            for (TblBeanBindingDetalleSuministroPedido deta : this.detallePedido) {

              DetalleMovimiento detall = new DetalleMovimiento();
              DetalleMovimientoPK detallepk= new DetalleMovimientoPK(correlativo, "");
              detall.setDetalleMovimientoPK(detallepk);
              detall.setCantidad(cantidadRequerida);
              detall.setCcosto(centro_costos);
              detall.setCodInv(cod_inversion);
              detall.setCodPresupuestal(cod_presupuestal);
              detall.setFecha(fecha_pedido);
              detall.setIdProyecto(cod_proyecto);
              detall.setIdSuministro(new Suministros(deta.getId_suministro()));
              detall.setId_unidad_organica(unidad_organica);
              detall.setPrecio(deta.getPrecio());
              detall.setIdLocalidad(null);
              detall.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(1)));
              detall.setValor((detall.getCantidad().multiply(detall.getPrecio()).setScale(2, RoundingMode.HALF_UP)));
              detall.setEstado_ubicacion(new Integer(0));
              correlativo++;
              detalle_ingresoDev.add(detall);
              }
             
             codMovimiento=GestionPedidosDelegate.getInstance().insertarSalidaInventario(Propiedades.getUsuario(), Propiedades.getMac(),mov ,detalle_ingresoDev, Listas.retornaInventario().getCodigo());

            }
          

    return codMovimiento;


   }
 
 public void GenerarReporte(String codigo){
     if(codigo!=null){
         JasperViewer jv = null;
        JasperPrint jp = null;
        Map parametros = new HashMap();
        parametros.put("idMovimiento", codigo);
        try {
            jp=GestionPedidosDelegate.getInstance().generarReporteIngreso("NotaSalidaFLP.jasper", parametros);
            jv = new JasperViewer(jp, false);
            jv.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
            jv.setVisible(true);
        }catch (Exception e) {
            Utiles_MensajesDialogo.mensajeError("No se pudo realizar la transaccion");
        }
     }
        
  }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cboBeanBindingTipo1 = new administracion.BeanBinding.CboBeanBindingTipo();
        cboBeanBindingTipo2 = new administracion.BeanBinding.CboBeanBindingTipo();
        cboBeanBindingLocalidad1 = new administracion.BeanBinding.CboBeanBindingLocalidad();
        jbtAceptar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtDetalleSuministro = new javax.swing.JTable();
        this.jtDetalleSuministro.getTableHeader().setReorderingAllowed(false) ;
        jButton3 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jtfFecha = new javax.swing.JFormattedTextField(this.mascaraFechaIngreso);
        jLabel4 = new javax.swing.JLabel();
        jtfSerie = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtfNumero = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtaObservacion = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jbtAceptar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbtAceptar.setMnemonic('A');
        jbtAceptar.setText("ACEPTAR");
        jbtAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAceptarActionPerformed(evt);
            }
        });
        jbtAceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtAceptarKeyPressed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jButton2.setMnemonic('C');
        jButton2.setText("CERRAR");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DETALLE DE SALIDA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 255))); // NOI18N
        jPanel1.setForeground(new java.awt.Color(0, 0, 255));

        jtDetalleSuministro.setFont(new java.awt.Font("Arial", 0, 12));
        jtDetalleSuministro.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CODIGO", "DENOMINACION", "CANTIDAD"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jtDetalleSuministro);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 595, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(5, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton3.setFont(new java.awt.Font("Arial", 1, 12));
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/view_text.png"))); // NOI18N
        jButton3.setMnemonic('V');
        jButton3.setText("VER NOTA SALIDA");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos de Ubicacion", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 12), new java.awt.Color(0, 0, 255))); // NOI18N
        jPanel3.setFont(new java.awt.Font("Arial", 0, 12));

        jLabel7.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel7.setText("Nº DOCUMENTO");

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel6.setText("FECHA:");

        jLabel1.setText("jLabel1");

        jLabel17.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel17.setText("EMPRESA");

        jtfFecha.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfFechaKeyPressed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel4.setText("SERIE");

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel5.setText("NUMERO");

        jLabel8.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel8.setText("OBSERVACION:");

        jtaObservacion.setColumns(20);
        jtaObservacion.setRows(5);
        jScrollPane1.setViewportView(jtaObservacion);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel17)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6)
                            .addComponent(jLabel8))
                        .addGap(23, 23, 23)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(jtfSerie, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 441, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(39, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jtfSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(17, 17, 17))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 612, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 612, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addComponent(jbtAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(jButton3)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtAceptar)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAceptarActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro que desea registrar la nota de salida?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){

                    if(this.jtfSerie.getText().compareTo("")==0 || this.jtfNumero.getText().compareTo("")==0){
                        Utiles_MensajesDialogo.mensajeFracaso("No se ha ingresado un pedido");
                    } else{
                        try {
                            codigoSalida=null;
                            codigoSalida=this.registrarSalida();
                            this.jbtAceptar.setEnabled(false);
                            Utiles_MensajesDialogo.mensajeExito();
                        } catch (Exception ex) {
                           
                            Utiles_MensajesDialogo.mensajeFracaso("No se pudo registrar la nota de salida "+ ex);
                        }
                    }

                try {

                } catch (Exception ex) {
                    Logger.getLogger(jdSalidasAjuste.class.getName()).log(Level.SEVERE, null, ex);
                }

        }
    }//GEN-LAST:event_jbtAceptarActionPerformed

    private void jbtAceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtAceptarKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtAceptar.doClick();
        }
}//GEN-LAST:event_jbtAceptarKeyPressed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            this.dispose();
        }
}//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

            if(codigoSalida!=null)
               this.GenerarReporte(codigoSalida);

    }//GEN-LAST:event_jButton3ActionPerformed

    private void jtfFechaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfFechaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtAceptar.requestFocus();
        }
}//GEN-LAST:event_jtfFechaKeyPressed

    /**
    * @param args the command line arguments
    */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.CboBeanBindingLocalidad cboBeanBindingLocalidad1;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo1;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo2;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbtAceptar;
    private javax.swing.JTable jtDetalleSuministro;
    private javax.swing.JTextArea jtaObservacion;
    private javax.swing.JFormattedTextField jtfFecha;
    private javax.swing.JTextField jtfNumero;
    private javax.swing.JTextField jtfSerie;
    // End of variables declaration//GEN-END:variables

}
